package com.learn.redis;

import redis.clients.jedis.Jedis;

public class Demo {
	private static final String REDIS_HOST = "192.168.0.199";

	public static void main(String[] args) throws Exception {
		Demo demo = new Demo();
		demo.test();
	}

	public void test() throws Exception {
		Jedis jedis = new Jedis(REDIS_HOST);

		long begin = System.currentTimeMillis();
		for (int i = 0; i < 20000; i++)
			jedis.get("key");
		long end = System.currentTimeMillis();
		System.out.println("jedis get20000次的执行时间：" + (end - begin) + "毫秒");

		begin = System.currentTimeMillis();
		for (int i = 0; i < 20000; i++)
			jedis.set(String.valueOf(i), String.valueOf(i));
		end = System.currentTimeMillis();
		System.out.println("jedis set 20000次的执行时间：" + (end - begin) + "毫秒");

		begin = System.currentTimeMillis();
		Thread t[] = new Thread[60];
		for (int j = 0; j < t.length; j++) {
			t[j] = new TestThread();
			t[j].start();
		}

		for (int j = 0; j < t.length; j++) {
			t[j].join();
		}
		end = System.currentTimeMillis();
		System.out.println("jedis 启动" + t.length + "个线程的执行时间：" + (end - begin)
				+ "毫秒");
	}

	class TestThread extends Thread {
		@Override
		public void run() {
			Jedis jedis = new Jedis(REDIS_HOST);
			for (int i = 0; i < 20000; i++)
				jedis.get(String.valueOf(i));
			jedis.disconnect();
		}

	}
}